package com.hnas.eCard.dao.impl;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.core.util.DateUtil;
import com.hnas.core.util.StringUtil;
import com.hnas.eCard.dao.CardOptLogDAO;
import com.hnas.eCard.orm.CardOptLog;

@Component("cardOptLogDAO")
public class CardOptLogDAOImpl extends BaseDaoImpl<CardOptLog> implements CardOptLogDAO {

	public CardOptLogDAOImpl() {
		super(CardOptLog.class);
	}

	@Override
	public CardOptLog saveOrUpdate(CardOptLog dto) {
		CardOptLog vo = null;
		try {
			if (null != dto) {
				if (StringUtil.isNotEmpty(dto.getId())) {
					vo = this.find(dto.getId());
				}

				if (null == vo) {
					vo = dto;
					vo.setCreateTime(DateUtil.dateTimeToString(new Date()));
					vo.setUpdateTime(DateUtil.dateTimeToString(new Date()));
					vo.setIsDeleted(false);
					this.persist(vo);
				} else {
					BeanUtils.copyProperties(dto, vo, new String[] { "id", "createTime"});
					vo.setUpdateTime(DateUtil.dateTimeToString(new Date()));
					this.merge(vo);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}

}
